<template>
	<view class="box">
		<view class="hezi" v-for="(item,index) in workList" :key="index">
			<view class="riqi xian">
				<view class="left">
					<image src="../../static/date.png" mode=""></image>
					<span>{{item.workDate}}</span>
				</view>
				<view v-if="strDate == item.workDate" class="right" @click="setinfo(item)">
					<button>修改</button>
				</view>
			</view>
			<view class="neir " :class="item.itemDateWorkList.length >1?'xian':''"  v-for="(it,ix) in item.itemDateWorkList" :key="ix">
				<view class="name">
					<span>项目名称 {{it.itemName}}</span>
				</view>
				<view class="danwei" v-if="username == 'cehui'">
					<span>单位：{{it.unitName}}</span>
					<span>项目工时：{{it.workTime}}</span>
					<span>工作量：{{it.workCount}}</span>
				</view>
				<view class="danwei" v-else>
					<span>项目工时：{{it.workTime}}</span>
				</view>
				<view class="xiangmu">
					<span>工作内容：{{it.workContent}}</span>
				</view>
			</view>
			<view class="tishi" v-if="item.workType == 2">
				<span>补录</span>
				<p>补录时间：{{item.workDate}}</p>
			</view>
		</view>
		<view class="" style="height: 60rpx;"></view>
		<view class="kong" v-if="workList.length == ''">
			<image class="img" src="../../static/kong.png" mode=""></image>
			<view class="text">
				暂无数据
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getworkList
	} from '@/common/http.api.js';
	export default{
		data(){
			return{
				username:uni.getStorageSync('name'),
				workList:[],
				params:{
					auditStatus:1,
					pageNum:1,
					pageSize:5
				},
				strDate:'',
			}
		},
		onShow() {
			this.workList = []
			this.getlist()
			this.currentTime()
		},
		methods:{
			currentTime() {
			    var date = new Date();
			    var year = date.getFullYear(); //月份从0~11，所以加一
			    let month = date.getMonth();
			    var dateArr = [
			        date.getMonth() + 1,
			        date.getDate(),
			        date.getHours(),
			        date.getMinutes(),
			        date.getSeconds(),
			    ];
			    //如果格式是MM则需要此步骤，如果是M格式则此循环注释掉
			    for (var i = 0; i < dateArr.length; i++) {
			        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
			            dateArr[i] = "0" + dateArr[i];
			        }
			    }
			    this.strDate =
			        year +
			        "-" +
			        dateArr[0] +
			        "-" +
			        dateArr[1] 
			        // " " +
			        // dateArr[2] +
			        // ":" +
			        // dateArr[3] +
			        // ":" +
			        // dateArr[4];
			        //此处可以拿外部的变量接收，也可直接返回  strDate:2022-05-01 13:25:30
			       	//this.date = strDate;
			    console.log("strDate",this.strDate);
			},
			getlist(){
				getworkList(this.params).then(res=>{
					if(res.code == 200){
						this.workList.push(...res.rows)
					}
				})
			},
			onReachBottom(){
				this.params.pageNum ++ 
				this.getlist()
			},
			setinfo(item){
				uni.navigateTo({
					url:`/pages/index/recording_work?id=${item.id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.kong{
		margin-top: 120rpx;
		.img{
			width: 300rpx;
			height: 300rpx;
		}
		.text{
			color: #CCCCCC;
			text-align: center;
		}
	}
	.tishi {
		display: flex;
		align-items: center;
		margin-top: 14rpx;
		span {
			width: 76rpx;
			height: 37rpx;
			background: #FFF3ED;
			border-radius: 10rpx;
			border: 1px solid #FF6410;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #FF6410;
			text-align: center;
			margin-right: 10rpx;
		}
		p {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #FF6410;
		}
	}

	.hezi {
		width: 660rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;
	}

	.xian {
		border-bottom: 2rpx #F1F1F1 solid;
	}

	.neir {
		margin-top: 20rpx;
		.name {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
		}
		.danwei {
			width: 80%;
			display: flex;
			justify-content: space-between;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 25rpx;
			color: #8F8F8F;
			margin: 10rpx 0rpx;
		}
		.xiangmu {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 25rpx;
			color: #8F8F8F;
			margin: 10rpx 0rpx;
		}
	}

	.riqi {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 90rpx;

		.left {
			display: flex;
			align-items: center;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
			}

			span {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #065CF7;
			}
		}

		.right {
			button {
				width: 109rpx;
				height: 50rpx;
				background: #065CF7;
				border-radius: 25rpx;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}

	.box {
		display: flex;
		flex-direction: column;
		align-items: center;

	}
</style>